﻿package com.utils
{
	import com.conf.PlayerSpec;
	import com.datasource.*;
	import com.datasource.interfaces.*;
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	// VOConverterUtils ::
	// - utilitaire de génération de VO
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public class VOConverterUtils
	{		
		static public function createWidgetObject( 	pName 	: String,
												  	pType 	: String,
													pParent : int,
													pOrder 	: Number
													
													) : WidgetSkinVO
		{
			var aObject : WidgetSkinVO 	= new WidgetSkinVO();
			
			allocateBaseProperties( aObject, pName, pType, pParent, pOrder );
			
			return aObject;
		}
		
		static public function createSimpleComponentObject( 	pName 	: String,
														   		pType 	: String,
																pParent : int,
																pOrder 	: Number
																
																) : SimpleComponentSkinVO
		{
			var aObject : SimpleComponentSkinVO 	= new SimpleComponentSkinVO();
			
			allocateBaseProperties( aObject, pName, pType, pParent, pOrder );
			
			return aObject;
		}
		
		static public function createComponentObject( 	pName 	: String,
													 	pType 	: String,
														pParent : int,
														pOrder 	: Number,
														pWidth	: Number,
														pHeight	: Number,
														pX		: Number,
														pY		: Number
														
														) : ComponentSkinVO
		{
			var aObject : ComponentSkinVO 	= new ComponentSkinVO();
			
			allocateBaseProperties( aObject, pName, pType, pParent, pOrder );
			
			allocateLayoutProperties( aObject, pWidth, pHeight, pX, pY );
			
			return aObject;
		}
		
		static public function createElementObject( 	pName 	: String,
													 	pType 	: String,
														pParent : int,
														pOrder 	: Number,
														pWidth	: Number,
														pHeight	: Number,
														pX		: Number,
														pY		: Number,
														pUrl	: String,
														pRef	: String
														
														) : ElementSkinVO
		{
			var aObject : ElementSkinVO 	= new ElementSkinVO();
			
			allocateBaseProperties( aObject, pName, pType, pParent, pOrder );
			
			allocateLayoutProperties( aObject, pWidth, pHeight, pX, pY );
			
			allocateSourceProperty( aObject, pUrl, pRef );
			
			return aObject;
		}
		
		static public function createLoaderObject( 	pName 	: String,
												  	pType 	: String,
													pParent : int,
													pOrder 	: Number
													
													) : LoaderSkinVO
		{
			var aObject : LoaderSkinVO 	= new LoaderSkinVO();
			
			allocateBaseProperties( aObject, pName, pType, pParent, pOrder );
			
			return aObject;
		}
		
		static private function allocateBaseProperties( 	aObject	: ISimpleSkinVO,
															pName 	: String,
															pType 	: String,
															pParent : int,
															pOrder 	: Number
															
															) : void
		{
			aObject[ PlayerSpec.PROPERTY_NAME ]		= String 	( pName );
			aObject[ PlayerSpec.PROPERTY_TYPE ]		= String 	( pType );
			aObject[ PlayerSpec.PROPERTY_PARENT ]		= int		( pParent );
			aObject[ PlayerSpec.PROPERTY_ORDER ]		= Number	( pOrder );
		}
		
		static private function allocateLayoutProperties( 	aObject 	: IPositionableSkinVO,
															pWidth 		: Number = 0,
															pHeight 	: Number = 0,
															pX 			: Number = 0,
															pY 			: Number = 0
															
															) : void
		{
			aObject[ PlayerSpec.PROPERTY_WIDTH ]		= Number	( pWidth );
			aObject[ PlayerSpec.PROPERTY_HEIGHT ]		= Number	( pHeight );
			aObject[ PlayerSpec.PROPERTY_X ]			= Number	( pX );
			aObject[ PlayerSpec.PROPERTY_Y ]			= Number	( pY );
		}
		
		static private function allocateSourceProperty(	aObject		: ILoadableSkinVO,
														pUrl		: String = null,
														pRef		: String = null
														
														) : void
		{
			aObject[ PlayerSpec.PROPERTY_URL ]		= String	( PlayerSpec.SKIN_REPOSITORY + pRef + "/" + PlayerSpec.IMG_REPOSITORY + pUrl + PlayerSpec.PNG_FORMAT );
		}
	}
}